
#import "ZHMWMultiRowTitleView.h"

@interface ZHMWMultiRowTitleView ()


@end

static NSDateFormatter* dateFormatter;

@implementation ZHMWMultiRowTitleView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubViews];
    }
    return self;
}

#pragma mark - Setter
- (void)setTitle:(NSString *)title {
    _titleLab.text = title;
}
- (void)setTime:(NSTimeInterval)time {
    _time = time;
    NSString *day = [self.class mw_formatDateStr:time withStyle:@"M月dd日"];
    NSString *hour = [self.class mw_formatDateStr:time withStyle:@"HH:mm"];
    NSString *totalValue = [NSString stringWithFormat:@"%@\n%@",day,hour];
    NSMutableAttributedString * mAttrStr = [[NSMutableAttributedString alloc]initWithString:totalValue];
    [mAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:[totalValue rangeOfString:day]];
    [mAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:[totalValue rangeOfString:hour]];
    _titleLab.attributedText = mAttrStr;
}


#pragma mark - Subviews
- (void)configSubViews {

    self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width-40, self.bounds.size.height)];
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.numberOfLines = 0;
    self.titleLab.textColor = [UIColor whiteColor];
    self.titleLab.font = [UIFont systemFontOfSize:14];
    self.titleLab.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self addSubview:self.titleLab];
}
#pragma mark - intrinsicContentSize
//- (CGSize)intrinsicContentSize
//{
//    return UILayoutFittingExpandedSize;
//}
#pragma mark - date
+ (NSString *)mw_formatDateStr:(NSTimeInterval )timeStamp withStyle:(NSString*)style
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dateFormatter = [[NSDateFormatter alloc] init];
    });
    timeStamp = timeStamp / 1000.;
    dateFormatter.dateFormat = style;
    NSDate* receiveDate = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    return [dateFormatter stringFromDate:receiveDate];
}
@end
